package com.wsoft.system.controller;

import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import com.wsoft.system.dto.SysLevelDTO;
import com.wsoft.system.query.level.SysLevelReq;
import com.wsoft.system.service.ISysLevelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 职务级别 前端控制器
 * @author juiet
 * @since 2024年09月11日 15:07:09
 */
@RestController
@Tag(name = "职务级别管理")
@RequestMapping("/sys/level")
public class SysLevelController {
    @Resource
    private ISysLevelService levelService;
    @Operation(summary = "新增职务级别",description = "新增职务级别")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid SysLevelDTO dto) {
        boolean b = levelService.insert(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑职务级别",description = "编辑职务级别")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid SysLevelDTO dto) {
        boolean b = levelService.update(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "删除职务级别",description = "删除职务级别")
    @ApiResponse(responseCode = "200", description = "OK")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = levelService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "查看职务级别详情",description = "查看职务级别详情")
    @ApiResponse(responseCode = "200", description = "OK")
    @GetMapping("/get")
    public ResponseResult getLevel(@RequestParam("id") Long id) {
        return ResponseResult.success(levelService.getLevelById(id));
    }

    @Operation(summary = "职务级别列表",description = "分页")
    @PostMapping("/list")
    public ResponseResult pageList(@RequestBody @Valid SysLevelReq req) {
        return ResponseResult.success(ResponsePage.restPage(levelService.pageLevel(req)));
    }
}
